package app.caihan.wanandroid.model.bean

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import app.caihan.wanandroid.model.db.converters.ArticlesTypeConverters
import app.caihan.wanandroid.model.db.converters.ChildChapterTypeConverters
import app.caihan.wanandroid.model.db.converters.TagsTypeConverters
import java.io.Serializable

/**
 *
 *
 * @author Seven-C
 * @date 2020/7/27
 */


/**
 * "desc": "享学~",
 * "id": 29,
 * "imagePath": "https://www.wanandroid.com/blogimgs/8e95ad05-a6f5-4c65-8a89-f8d4b819aa80.jpeg",
 * "isVisible": 1,
 * "order": 0,
 * "title": "做了5年Android，靠这份面试题和答案从12K涨到30K",
 * "type": 0,
 * "url": "https://mp.weixin.qq.com/s/oxoocfuPBS-fYI1Y0HU5QQ"
 */
@Entity
data class BannerBean(
    val desc: String,
    @PrimaryKey
    val id: Int,
    val imagePath: String,
    val isVisible: Int,
    val order: Int,
    val title: String,
    val type: Int,
    val url: String
)

/**
 *"curPage": 1,
 *"datas": [],
 *"offset": 0,
 *"over": false,
 *"pageCount": 454,
 *"size": 20,
 *"total": 9073
 */
@Entity
@TypeConverters(ArticlesTypeConverters::class)
data class PageList(
    val offset: Int,
    val size: Int,
    val total: Int,
    val pageCount: Int = 0,
    val curPage: Int = 0,
    val over: Boolean,
    val datas: List<Article> = emptyList()
)

/**
 * "apkLink": "",
 * "audit": 1,
 * "author": "",
 * "canEdit": false,
 * "chapterId": 182,
 * "chapterName": "JNI编程",
 * "collect": false,
 * "courseId": 13,
 * "desc": "",
 * "descMd": "",
 * "envelopePic": "",
 * "fresh": true,
 * "id": 14879,
 * "link": "https://juejin.im/post/6862732328406351879",
 * "niceDate": "14小时前",
 * "niceShareDate": "15小时前",
 * "origin": "",
 * "prefix": "",
 * "projectLink": "",
 * "publishTime": 1597933979000,
 * "realSuperChapterId": 128,
 * "selfVisible": 0,
 * "shareDate": 1597933672000,
 * "shareUser": "鸿洋",
 * "superChapterId": 182,
 * "superChapterName": "JNI",
 * "tags": [],
 * "title": "Android敏感数据泄露引发的思考",
 * "type": 0,
 * "userId": 2,
 * "visible": 1,
 * "zan": 0
 */
@Entity
@TypeConverters(TagsTypeConverters::class)
data class Article(
    @PrimaryKey(autoGenerate = true)
    var primaryKeyId: Int = 0,
    val apkLink: String = "",
    val audit: Int = 0,
    val author: String = "",
    val canEdit: Boolean = false,
    val chapterId: Int = 0,
    val chapterName: String = "",
    val collect: Boolean = false,
    val courseId: Int = 0,
    val desc: String = "",
    val descMd: String = "",
    val envelopePic: String = "",
    val fresh: Boolean = false,
    val id: Int = 0,
    val link: String = "",
    val niceDate: String = "",
    val niceShareDate: String = "",
    val origin: String = "",
    val prefix: String = "",
    val projectLink: String = "",
    val publishTime: Long = 0,
    val realSuperChapterId: Int = 0,
    val selfVisible: Int = 0,
    val shareDate: Long = 0,
    val shareUser: String = "",
    val superChapterId: Int = 0,
    val superChapterName: String = "",
    val tags: List<Tag> = emptyList(),
    val title: String = "",
    val type: Int = 0,
    val userId: Int = -1,
    val visible: Int = 0,
    val zan: Int = 0
)

/**
 *  "name": "公众号",
 *  "url": "/wxarticle/list/415/1"
 */
@Entity
data class Tag(
    @PrimaryKey(autoGenerate = true)
    var id: Long,
    @ColumnInfo(name = "article_id")
    var articleId: Long,
    val name: String,
    val url: String
)

/**
 *"children": [],
 *"courseId": 13,
 *"id": 408,
 *"name": "鸿洋",
 *"order": 190000,
 *"parentChapterId": 407,
 *"userControlSetTop": false,
 *"visible": 1
 */
@Entity
@TypeConverters(ChildChapterTypeConverters::class)
data class Chapters(
    /**
     * 实体和Pojos必须有一个可用的公共构造函数
     * https://blog.csdn.net/qq_34900897/article/details/103904089
     */
//    @Ignore
    val children: List<ChildChapters> = emptyList(),
    val courseId: Int,
    @PrimaryKey(autoGenerate = true)
    val id: Int,
    val name: String,
    val order: Int,
    val parentChapterId: Int,
    val visible: Int,
    val userControlSetTop: Boolean = false
) {

    data class ChildChapters(
        val courseId: Int,
        val id: Int,
        val name: String,
        val order: Int,
        val parentChapterId: Int,
        val visible: Int,
        val userControlSetTop: Boolean = false
    )
}


/**
 *  分页数据的基类
 */
data class ApiPagerResponse<T>(
    var datas: T,
    var curPage: Int,
    var offset: Int,
    var over: Boolean,
    var pageCount: Int,
    var size: Int,
    var total: Int
) : Serializable {
    /**
     * 数据是否为空
     */
    fun isEmpty(): Boolean {

        return (datas as List<*>).size == 0
    }

    /**
     * 是否为刷新
     */
    fun isRefresh(): Boolean {
        //wanandroid 第一页该字段都为0
        return offset == 0
    }

    /**
     * 是否还有更多数据
     */
    fun hasMore(): Boolean {
        return !over
    }
}

/**
 * "admin":false,
 * "chapterTops":[],
 * "coinCount":0,
 * "collectIds":[],
 * "email":"",
 * "icon":"",
 * "id":65878,
 * "nickname":"sweet2o09",
 * "password":"",
 * "publicName":"sweet2o09",
 * "token":"",
 * "type":0,
 * "username":"sweet2o09"
 */
@Entity
data class User(
    val admin: Boolean = false,
    val coinCount: Int = 0,
    val email: String = "",
    val icon: String = "",
    @PrimaryKey
    val id: Int,
    val nickname: String = "",
    val password: String = "",
    val publicName: String = "",
    val token: String = "",
    val type: Int = 0,
    val username: String = ""
) {

    override fun equals(other: Any?): Boolean {
        return if (other is User) {
            this.id == other.id
        } else false
    }
}

/**
 * 常用网站
 * "icon": "",
 * "id": 17,
 * "link": "http://www.wanandroid.com/article/list/0?cid=176",
 * "name": "国内大牛博客集合",
 * "order": 1,
 * "visible": 1
 */
data class FriendBean(
    val icon: String,
    val id: Int,
    val link: String,
    val name: String,
    val order: Int,
    var userId: Int,
    val visible: Int
)

/**
 * 目前搜索最多的关键词
 * "id": 5,
 * "link": "",
 * "name": "动画",
 * "order": 2,
 * "visible": 1
 */
data class HotkeyBean(
    val id: Int,
    val link: String,
    val name: String,
    val order: Int,
    val visible: Int
)

/**
 * 导航数据
 * "articles": [],
 * "cid": 279,
 * "name": "求职招聘"
 */
data class NavigationBean(
    var articles: List<Article> = emptyList(),
    var cid: Int,
    var name: String
)

/**
 * 积分
 */
data class IntegralBean(
    var coinCount: Int,//当前积分
    var rank: Int,
    var userId: Int,
    var username: String,
    var date: Long,
    var desc: String,
    var id: Int,
    var type: Int,
    var reason: String,
    var userName: String
)


